package hello;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.HashMap;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;

import com.alibaba.fastjson.JSON;

public class testOrder {
	private static SimpleDateFormat  form = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public static void main(String[] args) {	
		//createOrder();
		//sendOrder();
		//modifyOk();
		refundOrder();
		//detail();
		//orderList();
		//orderListOfProduct();
    }
	
	public static void orderList(){
		HashMap<String, Object> map = new HashMap<String, Object>();
     	// map集合
        HashMap<String, Object> head = new HashMap<String, Object>();
        head.put("user_uuid", "fe34b39b2efb3f0202beb6dfe97d12fb");
        head.put("password", "123456");
        map.put("head", head);	
        
        HashMap<String, Object> body = new HashMap<String, Object>();
        
        body.put("account_uuid", "fe34b39b2efb3f0202beb6dfe97d12fb");
        map.put("body",body);
  
   	    String jsonString = JSON.toJSONString(map); 
   	    System.out.println(jsonString);

   	    String url = "https://weituan.huanba.me/mingai-admin-api/order/orderList";
 	    HttpPost httpPost = new HttpPost(url);
   	    StringEntity entity;
   	    entity = new StringEntity(jsonString, HTTP.UTF_8);
		entity.setContentType("application/json");
		httpPost.setEntity(entity);
		@SuppressWarnings("deprecation")
		HttpClient client = new DefaultHttpClient();
		try {
			HttpResponse response = client.execute(httpPost);
			//获取服务器返回页面的值
			HttpEntity entity2=response.getEntity();
			String xmlContent=EntityUtils.toString(entity2);
			System.out.println(java.net.URLDecoder.decode(xmlContent, "utf-8"));
			System.out.println(response.toString());

		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void orderListOfProduct(){
		HashMap<String, Object> map = new HashMap<String, Object>();
     	// map集合
        HashMap<String, Object> head = new HashMap<String, Object>();
        head.put("user_uuid", "fe34b39b2efb3f0202beb6dfe97d12fb");
        head.put("password", "123456");
        map.put("head", head);	
        
        HashMap<String, Object> body = new HashMap<String, Object>();
        
        body.put("productUuid", "14f1609a5de101204c4dfd8826248fb0");
        map.put("body",body);
  
   	    String jsonString = JSON.toJSONString(map); 
   	    System.out.println(jsonString);

   	    String url = "https://weituan.huanba.me/mingai-admin-api/order/orderListOfProduct";
 	    HttpPost httpPost = new HttpPost(url);
   	    StringEntity entity;
   	    entity = new StringEntity(jsonString, HTTP.UTF_8);
		entity.setContentType("application/json");
		httpPost.setEntity(entity);
		@SuppressWarnings("deprecation")
		HttpClient client = new DefaultHttpClient();
		try {
			HttpResponse response = client.execute(httpPost);
			//获取服务器返回页面的值
			HttpEntity entity2=response.getEntity();
			String xmlContent=EntityUtils.toString(entity2);
			System.out.println(java.net.URLDecoder.decode(xmlContent, "utf-8"));
			System.out.println(response.toString());

		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void createOrder(){
		HashMap<String, Object> map = new HashMap<String, Object>();
     	// map集合
        HashMap<String, Object> head = new HashMap<String, Object>();
        head.put("user_uuid", "fe34b39b2efb3f0202beb6dfe97d12fb");
        head.put("password", "123456");
        map.put("head", head);	
        
        HashMap<String, Object> body = new HashMap<String, Object>();
        
        body.put("account_uuid", "fe34b39b2efb3f0202beb6dfe97d12fb");
        body.put("productUuid", "2e4d6e424621645bc3708f77007933e8");
        body.put("addressUuid", "0b04e4fbf9e815b2d1ba706b1aca6bd8");
        body.put("totalPrice", 32.00f);
        body.put("realPrice", 29.52f);
        body.put("productCount", 7);
        map.put("body",body);
  
   	    String jsonString = JSON.toJSONString(map); 
   	    System.out.println(jsonString);

   	    String url = "http://192.168.1.135:8080/micro/order/create";
 	    HttpPost httpPost = new HttpPost(url);
   	    StringEntity entity;
   	    entity = new StringEntity(jsonString, HTTP.UTF_8);
		entity.setContentType("application/json");
		httpPost.setEntity(entity);
		@SuppressWarnings("deprecation")
		HttpClient client = new DefaultHttpClient();
		try {
			HttpResponse response = client.execute(httpPost);
			//获取服务器返回页面的值
			HttpEntity entity2=response.getEntity();
			String xmlContent=EntityUtils.toString(entity2);
			System.out.println(java.net.URLDecoder.decode(xmlContent, "utf-8"));
			System.out.println(response.toString());

		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void sendOrder(){
		HashMap<String, Object> map = new HashMap<String, Object>();
     	// map集合
        HashMap<String, Object> head = new HashMap<String, Object>();
        head.put("user_uuid", "fe34b39b2efb3f0202beb6dfe97d12fb");
        head.put("password", "123456");
        map.put("head", head);	
        
        HashMap<String, Object> body = new HashMap<String, Object>();
        
        body.put("account_uuid", "fe34b39b2efb3f0202beb6dfe97d12fb");
        body.put("orderUuid", "161207624662842");
        map.put("body",body);
  
   	    String jsonString = JSON.toJSONString(map); 
   	    System.out.println(jsonString);

   	    String url = "http://192.168.1.135:8080/micro/order/sendOrder";
 	    HttpPost httpPost = new HttpPost(url);
   	    StringEntity entity;
   	    entity = new StringEntity(jsonString, HTTP.UTF_8);
		entity.setContentType("application/json");
		httpPost.setEntity(entity);
		@SuppressWarnings("deprecation")
		HttpClient client = new DefaultHttpClient();
		try {
			HttpResponse response = client.execute(httpPost);
			//获取服务器返回页面的值
			HttpEntity entity2=response.getEntity();
			String xmlContent=EntityUtils.toString(entity2);
			System.out.println(java.net.URLDecoder.decode(xmlContent, "utf-8"));
			System.out.println(response.toString());

		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void modifyOk(){
		HashMap<String, Object> map = new HashMap<String, Object>();
     	// map集合
        HashMap<String, Object> head = new HashMap<String, Object>();
        head.put("user_uuid", "fe34b39b2efb3f0202beb6dfe97d12fb");
        head.put("password", "123456");
        map.put("head", head);	
        
        HashMap<String, Object> body = new HashMap<String, Object>();
        
        body.put("account_uuid", "fe34b39b2efb3f0202beb6dfe97d12fb");
        body.put("orderUuid", "161207624662842");
        map.put("body",body);
  
   	    String jsonString = JSON.toJSONString(map); 
   	    System.out.println(jsonString);

   	    String url = "http://192.168.1.135:8080/micro/order/modifyOk";
 	    HttpPost httpPost = new HttpPost(url);
   	    StringEntity entity;
   	    entity = new StringEntity(jsonString, HTTP.UTF_8);
		entity.setContentType("application/json");
		httpPost.setEntity(entity);
		@SuppressWarnings("deprecation")
		HttpClient client = new DefaultHttpClient();
		try {
			HttpResponse response = client.execute(httpPost);
			//获取服务器返回页面的值
			HttpEntity entity2=response.getEntity();
			String xmlContent=EntityUtils.toString(entity2);
			System.out.println(java.net.URLDecoder.decode(xmlContent, "utf-8"));
			System.out.println(response.toString());

		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void refundOrder(){
		HashMap<String, Object> map = new HashMap<String, Object>();
     	// map集合
        HashMap<String, Object> head = new HashMap<String, Object>();
        head.put("user_uuid", "fe34b39b2efb3f0202beb6dfe97d12fb");
        head.put("password", "123456");
        map.put("head", head);	
        
        HashMap<String, Object> body = new HashMap<String, Object>();
        
        body.put("account_uuid", "fe34b39b2efb3f0202beb6dfe97d12fb");
        body.put("orderUuid", "170212651111662");
        body.put("count", "7");
        body.put("applyMoney", 20.00f);
        body.put("explain", "不想买了");
        body.put("image", "图图图");
        map.put("body",body);
  
   	    String jsonString = JSON.toJSONString(map); 
   	    System.out.println(jsonString);

   	    String url = "https://weituan.huanba.me/mingai-admin-api/order/refund";
 	    HttpPost httpPost = new HttpPost(url);
   	    StringEntity entity;
   	    entity = new StringEntity(jsonString, HTTP.UTF_8);
		entity.setContentType("application/json");
		httpPost.setEntity(entity);
		@SuppressWarnings("deprecation")
		HttpClient client = new DefaultHttpClient();
		try {
			HttpResponse response = client.execute(httpPost);
			//获取服务器返回页面的值
			HttpEntity entity2=response.getEntity();
			String xmlContent=EntityUtils.toString(entity2);
			System.out.println(java.net.URLDecoder.decode(xmlContent, "utf-8"));
			System.out.println(response.toString());

		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void detail(){
		HashMap<String, Object> map = new HashMap<String, Object>();
     	// map集合
        HashMap<String, Object> head = new HashMap<String, Object>();
        head.put("user_uuid", "fe34b39b2efb3f0202beb6dfe97d12fb");
        head.put("password", "123456");
        map.put("head", head);	
        
        HashMap<String, Object> body = new HashMap<String, Object>();
        
        body.put("account_uuid", "fe34b39b2efb3f0202beb6dfe97d12fb");
        body.put("orderUuid", "161207624662842");
        map.put("body",body);
  
   	    String jsonString = JSON.toJSONString(map); 
   	    System.out.println(jsonString);

   	    String url = "http://192.168.0.5:8080/micro/order/detail";
 	    HttpPost httpPost = new HttpPost(url);
   	    StringEntity entity;
   	    entity = new StringEntity(jsonString, HTTP.UTF_8);
		entity.setContentType("application/json");
		httpPost.setEntity(entity);
		@SuppressWarnings("deprecation")
		HttpClient client = new DefaultHttpClient();
		try {
			HttpResponse response = client.execute(httpPost);
			//获取服务器返回页面的值
			HttpEntity entity2=response.getEntity();
			String xmlContent=EntityUtils.toString(entity2);
			System.out.println(java.net.URLDecoder.decode(xmlContent, "utf-8"));
			System.out.println(response.toString());

		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
